package OsType;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;




public class Linux implements OsType {
	private static final String execString="sh scripting/execstring.sh ";
	String incom;String outcom;
	public Linux(){
		try {
			File a;
			a = File.createTempFile("commandline", ".in");
			incom=a.getAbsolutePath();
			a.deleteOnExit();
			a = File.createTempFile("commandline", ".out");
			outcom=a.getAbsolutePath();
			a.deleteOnExit();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}
	public int getId(){
		return linux;
	}
	public Process execute(String dir,String com) throws IOException {
		FileWriter fw;
		fw=new FileWriter(incom);
		BufferedWriter bw = new BufferedWriter(fw);
		bw.write(com);
		bw.close();

		try {
			return Runtime.getRuntime().exec(execString+dir+" "+incom+" "+outcom);
		} catch (IOException e) {
			e.printStackTrace();
			return null;
		}
	}
	public String getText() {
		FileReader fr=null;
		BufferedReader br =null;
		String tmp=null;
		String monitor_text="";
		try {
			fr = new FileReader(outcom);
		} catch (FileNotFoundException e1) {
			e1.printStackTrace();
		}
		br=new BufferedReader(fr);
		
		try {
			tmp = br.readLine();
	
		

		while (tmp!=null){
			monitor_text+=tmp+"\n";
	
				tmp=br.readLine();
			}
		} catch (IOException e) {
		e.printStackTrace();
		}
		
		return monitor_text;
	}


}

